<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form" id="bdForm" style="margin-left: 5%">
    <input name="bdTeamCodeId" id="bdTeamCodeId" type="hidden"/>
    <br/>
    <div class="layui-input-inline">
        <a id="down" class="layui-btn layui-btn-radius" download="兑换码明细.csv" href="#">导出</a>
    </div>
</form>
<table class="layui-table" id="grid" lay-filter="grid">
</table>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var tableIns;
    var successCallback;
    var bdTeamCodeId = getQueryString("bdTeamCodeId");
    $("#bdTeamCodeId").val(bdTeamCodeId);

    form.on('submit(addCodeBtn)', function () {
        openDialog({
            url: "/backend/security/bdTeamCode/detail?bdTeamId="+bdTeamId,
            area: ["80%", "95%"]
        });
        return false;
    });

    $('#down').on('click', function (aLink) {
        var table = layui.table;
        var tab = table.cache.grid;
        var status;
        var incomeAfterRefundFee;
        var str = "兑换码,使用情况\n";
        $.each(tab, function (i, row) {
            if(row["status"]==0){
                status="未使用";
            }else{
                status="已使用";
            }
            str = str + row["code"] + "," + status + "\n";
        });
        str = encodeURIComponent(str);
        aLink.target.href = "data:text/csv;charset:utf-8,\ufeff" + str;
    });


    $(function () {
        tableIns = createTable({
            url: '/backend/security/bdTeamCodeLog/list?bdTeamCodeId='+bdTeamCodeId,
            cols: [[
                {field: 'code', title: '兑换码', width: 250}
                ,{field: 'status', title: '使用情况', width: 150, templet: '#statusTpl'}
            ]],limit: 500
        });
    });
</script>
<script type="text/html" id="statusTpl">
    {{#  if(d.status ===1){ }}
    <span style="color: #FF0000;">已使用</span>
    {{#  } else { }}
    <span style="color: green;">未使用</span>
    {{#  } }}
</script>
</body>
</html>